﻿using log4net;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using Hjt212Parser;
using WinService_DatabaseMaintain.Properties;

namespace WinService_DatabaseMaintain
{
    public partial class ServiceDatabaseMaintain : ServiceBase
    {
        private static ILog Log = LogManager.GetLogger(typeof(ServiceDatabaseMaintain));

        public ServiceDatabaseMaintain()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            new Thread(Process) { IsBackground = true }.Start();
            Log.Info("服务启动成功。");
        }

        private void Process()
        {
            while (true)
            {
                var begin = DateTime.Now;
                Log.Info("处理开始:"+begin);
                DbMovingBackup.BackupRealData();
                DbMovingBackup.BackupMinuteData();
                DbMovingBackup.BackupHourData();

                Log.Info("处理结束:" + begin + ",耗时(分钟)：" + (DateTime.Now - begin).TotalMinutes);

                ThreadUtil.Sleep(Settings.Default.intervalMinutes*60*1000);
            }

        }

        protected override void OnStop()
        {
        }
    }
}
